﻿using System;
using Microsoft.Practices.ObjectBuilder;
using System.Collections.Generic;
using AP.LUNA.DataEntities;
using System.Web.UI.WebControls;

namespace AP.LUNA.Shell.Views
{
    public partial class RegistrarNotas : Microsoft.Practices.CompositeWeb.Web.UI.UserControl, IRegistrarNotasView
    {
        private RegistrarNotasPresenter _presenter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this._presenter.OnViewInitialized();
            }
            this._presenter.OnViewLoaded();
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.Presenter.ObtenerTemas();
        }

        [CreateNew]
        public RegistrarNotasPresenter Presenter
        {
            get
            {
                return this._presenter;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                this._presenter = value;
                this._presenter.View = this;
            }
        }

        // TODO: Forward events to the presenter and show state to the user.
        // For examples of this, see the View-Presenter (with Application Controller) QuickStart:
        //	

        protected void GenerarGrid()
        {
            int tema = 0;
            gvNotas.DataKeyNames = new string[] { "IdAlumno" };
            gvNotas.Columns.Clear();

            TemplateField itemAlumno = new TemplateField();
            itemAlumno.HeaderText = "Estudiante";
            itemAlumno.ItemTemplate = new GridViewItemTemplate("NombreCompleto");
            gvNotas.Columns.Add(itemAlumno);

            foreach (desempenos item in this.ListaDesempenos)
            {
                tema++;
                TemplateField itemTemplate = new TemplateField();
                itemTemplate.HeaderText = item.Descripcion + " (" + item.PorcentajeMostrar + ")";
                itemTemplate.ItemTemplate = new GridViewEditTemplate("Nota" + tema.ToString());
                gvNotas.Columns.Add(itemTemplate);
            }
        }

        List<desempenos> _ListaDesempenos = new List<desempenos>();
        public List<desempenos> ListaDesempenos
        {
            get
            {
                return _ListaDesempenos;
            }
            set
            {
                _ListaDesempenos = value;
            }
        }
    }
}

